#include "widget.h"
#include "ui_widget.h"
#include<QPainter>
#include<QTimer>
#include<QPushButton>
#include<QIcon>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置主界面
    setFixedSize(700,1000);
    setWindowTitle("飞机大战1.08");
    setWindowIcon(QPixmap(":/tpw/logo.jpeg"));
    //开始游戏按钮的实现  首先new一个游戏界面，点击后主界面隐藏，游戏界面出现
    connect(ui->btn1,&QPushButton::clicked,[=](){
        playpage=new PlayPage;//这样让游戏页面不会一开始就初始化。避免了打开主页面过久才开始游戏时敌机已飞出的bug
        this->hide();
        playpage->show();
        connect(playpage,SIGNAL(sendsignal()),this,SLOT(reshow()));//当点击子界面时，调用主界面的reshow()函数
    });
    //关闭游戏按钮
    connect(ui->btn2,&QPushButton::clicked,this,&QWidget::close);


}

Widget::~Widget()
{
    delete ui;
}
//背景与图标的绘制
void Widget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.drawPixmap(0,0,700,1000,QPixmap(":/tpw/background"));
    painter.drawPixmap(30,100,QPixmap(":/tpw/logo"));
}

void Widget::reshow()
{
    this->show();
}
